package com.runlooker.runer.entity;

import net.tsz.afinal.annotation.sqlite.Table;

import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Presence.Type;

import com.runlooker.runer.db.RunerTableSql;

@Table(name = RunerTableSql.PRESENCE_ENTRY_TABLE)
public class PresenceEntity {
	private static final String tag = PresenceEntity.class.getSimpleName();
	// available -- 通知实体可通信.
	// unavailable -- 通知实体将不可通信.
	// subscribe -- 发送者希望订阅接收者的出席信息.
	// subscribed -- 发送者允许接收者接收他们的出席信息.
	// unsubscribe -- 发送者取消订阅另一个实体的出席信息.
	// unsubscribed -- 订阅者的请求被拒绝或以前的订阅被取消.
	// error -- 处理或递送之前发送的出席信息节的时候发生了错误.
	public static final int error = 0;
	public static final int unsubscribed = 1;
	public static final int subscribed = 2;
	public static final int subscribe = 3;
	public static final int unavailable = 4;
	public static final int available = 5;
	public static final int unsubscribe = 6;

	private String fromAccount;
	private int precenceType;

	public static int parsetype(Type Str) {
		int type = 0;
		if (Str == null) {
			return type;
		}

		if (Str.equals(Presence.Type.subscribe)) {
			type = subscribe;
		} else if (Str.equals(Presence.Type.subscribed)) {
			type = subscribed;
		} else if (Str.equals(Presence.Type.unsubscribed)) {
			type = unsubscribed;
		} else if (Str.equals(Presence.Type.unsubscribe)) {
			type = unsubscribe;
		} else if (Str.equals(Presence.Type.unavailable)) {
			type = unavailable;
		} else if (Str.equals(Presence.Type.available)) {
			type = available;
		} else if (Str.equals(Presence.Type.error)) {
			type = error;
		}

		return type;
	}

	public int getPrecenceType() {
		return precenceType;
	}

	public void setPrecenceType(int precenceType) {
		this.precenceType = precenceType;
	}

	public String getFromAccount() {
		return fromAccount;
	}

	public void setFromAccount(String fromAccount) {
		this.fromAccount = fromAccount;
	}

	@Override
	public String toString() {
		return "from:  " + fromAccount + ",   Type:  " + precenceType;
	}

}
